package love.bot.forli.group.review.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import love.bot.forli.group.review.bean.Dto.TypeDto;
import love.bot.forli.group.review.bean.Result;
import love.bot.forli.group.review.bean.Vo.AddTypeVo;
import love.bot.forli.group.review.bean.Vo.TypeRuleVo;
import love.bot.forli.group.review.entity.QuestionType;
import love.bot.forli.group.review.service.QuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Kontori
 */
@Api(tags = "题组类型相关接口")
@RestController
@RequestMapping("/questionType")
@Transactional(rollbackFor = {Throwable.class})
public class QuestionTypeController {

    private QuestionTypeService questionTypeService;

    @Autowired
    public void setQuestionTypeService(QuestionTypeService questionTypeService) {
        this.questionTypeService = questionTypeService;
    }

    @ApiOperation("获取所有题组类型")
    @GetMapping("/list")
    public Result<List<TypeDto>> typeList() {
        return questionTypeService.listType();
    }

    @ApiOperation("新增题组类型")
    @PostMapping("/add")
    public Result<Object> addType(@RequestBody AddTypeVo addTypeVo) {
        return questionTypeService.addType(addTypeVo);
    }

    @ApiOperation("删除题组类型")
    @DeleteMapping("/delete/{typeId}")
    public Result<Object> deleteType(@PathVariable("typeId") Integer questionTypeId) {
        return questionTypeService.deleteType(questionTypeId);
    }

    @ApiOperation("修改题组类型")
    @PostMapping("/editQuestionType")
    public Result<Object> editQuestionType(@RequestBody QuestionType questionType) {
        return questionTypeService.updateById(questionType) ?
                Result.success("修改成功", null) : Result.fail("修改失败");
    }

    @ApiOperation("更新题组类型抽取数量")
    @PostMapping("/rule")
    public Result<String> typeRule(@RequestBody TypeRuleVo typeRuleVo) {
        return questionTypeService.updateRule(typeRuleVo);
    }
}
